﻿using System;
using System.ComponentModel;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;

namespace Mari.SmartHotel.Controls
{
    /// <summary>
    /// Interaction logic for MainPaneClock.xaml
    /// </summary>
    public partial class MainPaneEmpty : UserControl
    {
        Timer timer = new Timer(1000);

        public MainPaneEmpty()
        {
            InitializeComponent();

            if (DesignerProperties.GetIsInDesignMode(this))
                return;

            timer.Elapsed += timer_Elapsed;
            timer.Enabled = true;
        }

        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
            {
                secondHand.Angle = DateTime.Now.Second * 6;
                minuteHand.Angle = DateTime.Now.Minute * 6;
                hourHand.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5);
            }));
        }

        private void usrClock_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            timer.Enabled = (bool)e.NewValue;
        }
    }
}
